#include "./include/stdio.h"
#include "./include/int_call.h"

void print_string(char * pstr, unsigned char row, unsigned char col, unsigned char color)
{
        int i;
        char * screenBuf;
        
        screenBuf += row * 160 + col * 2;
        while(*pstr)
        {
                screenBuf = row * 160 + col++ * 2 + (char *)0xb8000;
                *screenBuf++ = *pstr++;
                *screenBuf = color;
                if(col == 80)
                {
                        col = 0;
                        row++;
                }
                if(row == 25)
                {
                        row = 0;
                }
         
        }
}

void out_hex_byte(unsigned char ch, unsigned char row, unsigned char col, unsigned char color)
{
        char num[3];
        char * screenBuf;
        
        num[2] = 0;
        num[0] = (ch >> 4) & 0x0f;
        if(num[0] >= 0 && num[0] <= 9)
                num[0] |= 0x30;
        else
                num[0] += 55;
                
        num[1] = ch & 0x0f;
        if(num[1] >= 0 && num[1] <= 9)
                num[1] |= 0x30;
        else
                num[1] += 55;
        
        print_string(num, row, col, color);
}


void out_hex_word(unsigned short ch, unsigned char row, unsigned char col, unsigned char color)
{
        out_hex_byte((unsigned char)(ch >> 8), row, col, color);
        out_hex_byte((unsigned char)ch, row, col + 2, color);
}


void out_hex_dword(unsigned int ch, unsigned char row, unsigned char col, unsigned char color)
{
        out_hex_word((unsigned short)(ch >> 16), row, col, color);
        out_hex_word((unsigned short)(ch), row, col + 4, color);
}

void clearScreen()
{
	Reg_Struct regs;
	regs.ax = 0x0600;
        regs.bx = 0x0000;
        regs.cx = 0x0000;
        regs.dx = 0x184f;
        regs.si = 5;
        regs.di = 6;
        regs.es = 0;
        regs.ds = 0;
        int_call(0x10, &regs);
}
